package util;

import java.sql.*;
import java.util.ResourceBundle;

public class JDBCUtils {

    //static静态，直接使用类名.方法名更方便
    public static Connection getconnection() throws Exception{
        //        使用资源绑定器绑定属性配置文件
        ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
        String driver = bundle.getString("driver");
        String url = bundle.getString("url");
        String user = bundle.getString("user");
        String password = bundle.getString("password");
        Class.forName(driver);

        Connection conn=DriverManager.getConnection(url,user,password);
        return conn;
    }
    //释放资源
    public static void release(ResultSet rs, Statement stat, Connection conn) throws Exception{
        if(rs!=null){
            rs.close();
        }
        if(stat!=null){
            stat.close();
        }
        if(conn!=null){
            conn.close();
        }
    }
}